package com.ayf.payment.game.api.service.impl;

import com.ayf.payment.game.api.dto.GamePlayerCashOrderBlacklistDTO;
import com.ayf.payment.game.api.dto.criteria.GamePlayerCashOrderBlacklistPageCriteria;
import com.ayf.payment.game.api.entity.GamePlayerCashOrderBlacklist;
import com.ayf.payment.game.api.mapper.GamePlayerCashOrderBlacklistMapper;
import com.ayf.payment.game.api.service.GamePlayerCashOrderBlacklistService;
import com.ayf.payment.game.api.type.PlayerCashOrderBlacklistEnum;
import com.ayf.payment.game.api.utils.DateUtils;
import com.swwx.charm.commons.lang.utils.BeanConvertUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional(rollbackFor = Throwable.class)
public class GamePlayerCashOrderBlacklistServiceImpl implements GamePlayerCashOrderBlacklistService{

    @Resource
    private GamePlayerCashOrderBlacklistMapper gamePlayerCashOrderBlacklistMapper;

    @Override
    public void addPlayerCashOrderBlacklist(GamePlayerCashOrderBlacklistDTO criteria) {
        GamePlayerCashOrderBlacklist upGamePlayerCashOrderBlacklist = BeanConvertUtils.convert(criteria,GamePlayerCashOrderBlacklist.class);
        if (criteria.getId() == null){
            upGamePlayerCashOrderBlacklist.setCreateTime(DateUtils.getNowDate());
            gamePlayerCashOrderBlacklistMapper.insert(upGamePlayerCashOrderBlacklist);
        } else {
            gamePlayerCashOrderBlacklistMapper.updateByPrimaryKeySelective(upGamePlayerCashOrderBlacklist);
        }
    }

    @Override
    public void deletePlayerCashOrderBlacklist(Integer id) {
        gamePlayerCashOrderBlacklistMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<GamePlayerCashOrderBlacklistDTO> list(GamePlayerCashOrderBlacklistPageCriteria criteria) {
        return BeanConvertUtils.convert(gamePlayerCashOrderBlacklistMapper.list(criteria),GamePlayerCashOrderBlacklistDTO.class);
    }

    @Override
    public boolean checkBlacklist(Integer merchantId,String accountNo, PlayerCashOrderBlacklistEnum aliapy) {
        Example example =new Example(GamePlayerCashOrderBlacklist.class);
        Example.Criteria criteria =  example.createCriteria();
        criteria.andEqualTo("merchantId",merchantId);
        criteria.andEqualTo("name",accountNo);
        criteria.andEqualTo("type",aliapy.getCode());
        int result =  gamePlayerCashOrderBlacklistMapper.selectCountByExample(example);
        return result>0?true:false;
    }
}
